package com.csproj.siiat.base.common.util;

import org.apache.commons.lang3.StringUtils;

/**
 * Utility class for generating random Strings.
 */
public final class CodeFactory {

    /**
     * 根据父级parent_code与no，生成code
     * @author LM
     * @param no  排序
     * @param parentCode 父级任务
     * @return
     */
    public static String createCode(Integer no,String parentCode){
        if(StringUtils.isBlank(parentCode)){
            parentCode="ROOT_";
        }
        if("ROOT_".equals(parentCode) || "root_".equals(parentCode)){
            char ABC='A';
            String code = String.valueOf(ABC)+no+"_";
            return code;
        }
        int _index = parentCode.substring(0, parentCode.length()-2).lastIndexOf("_");
        if(_index == -1){
            String code = parentCode+"B"+no+"_";
            return code;
        }
        char ABC = parentCode.charAt(_index+1);
        String code = parentCode+String.valueOf((char)(ABC+1))+no+"_";
        return code;
    }
}
